﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace NP.BPMReportPlatform.SF.Dto
{
    public class SFPickResultDto: SFResultBase
    {
        /// <summary>
        /// 选项列表ID
        /// POSITION_CLASSIFICATION：职位分类；ProfessionalCategories：专业类；Professional：专业
        /// </summary>
        [JsonProperty("picklistId")]
        public string PicklistId { get; set; }

        /// <summary>
        /// 下拉值列表
        /// </summary>
        [JsonProperty("picklistOptions")]
        public SFResponseDate<SFPickOptionsDto> PicklistOptions { get; set; }

        /// <summary>
        /// 下拉值
        /// </summary>
        public class SFPickOptionsDto : SFResultBase
        {
            /// <summary>
            /// 下拉值ID
            /// </summary>
            [JsonProperty("externalCode")]
            public string ExternalCode { get; set; }

            /// <summary>
            /// 下拉值ID
            /// </summary>
            [JsonProperty("id")]
            public string OptionId { get; set; }

            /// <summary>
            /// 下拉值状态
            /// Active/Inactive,BPM筛选Active的使用
            /// </summary>
            [JsonProperty("status")]
            public string Status { get; set; }

            /// <summary>
            /// 下拉值名称列
            /// </summary>
            [JsonProperty("picklistLabels")]
            public SFResponseDate<SFPickLabelDto> PicklistLabels { get; set; }
        }

        /// <summary>
        /// 下拉值名称选项
        /// </summary>
        public class SFPickLabelDto : SFResultBase
        {
            /// <summary>
            /// 下拉值名称
            /// </summary>
            [JsonProperty("locale")]
            public string Local { get; set; }

            /// <summary>
            /// 下拉值名称语言环境
            /// </summary>
            [JsonProperty("label")]
            public string Label { get; set; }

            /// <summary>
            /// 下拉值名称语言环境
            /// </summary>
            [JsonProperty("optionId")]
            public string OptionId { get; set; }

            /// <summary>
            /// 下拉值名称语言环境
            /// </summary>
            [JsonProperty("picklistOption")]
            public SFPickListOptionDto PicklistOption { get; set; }
        }

        /// <summary>
        /// SFPickListOptionDto
        /// </summary>
        public class SFPickListOptionDto : SFResultBase
        {
            /// <summary>
            /// 下拉值名称语言环境
            /// </summary>
            [JsonProperty("parentPicklistOption")]
            public SFParentPickListOptionDto ParentPickListOption { get; set; }
        }

        /// <summary>
        /// 下拉值名称选项
        /// </summary>
        public class SFParentPickListOptionDto : SFResultBase
        {
            /// <summary>
            /// 下拉值名称列
            /// </summary>
            [JsonProperty("picklistLabels")]
            public SFResponseDate<SFPickLabelDto> PicklistLabels { get; set; }
        }

        public class JsonObjectToStringConverter : JsonConverter
        {
            public override bool CanConvert(Type objectType)
            {
                // 指定该Converter适用于所有类型
                return true;
            }
            public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
            {
                // 直接读取JSON对象作为字符串
                return reader.ReadAsString();
            }
            public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
            {
                // 直接将字符串写入JSON
                writer.WriteValue(value.ToString());
            }
        }
    }
}
